home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ca29_3.zip / KERMSERV.CMD < prev    next >
OS/2 REXX Batch file  |  1988-09-13  |  3KB  |  152 lines

  1. ;    Kermit server command script file
  2. ;    ---------------------------------
  3. ;    Commenced: 6/8/88 R.McG
  4. ;
  5. ;    First - open a window
  6. ;
  7.     ON ESCAPE GOSUB Exit        ; Exit if esc pressed
  8. Restart:
  9.     GOSUB Window            ; Open window and ask for command
  10. ;
  11. ;    S0 returns the response: Interpret the response
  12. ;
  13.     SWITCH S0
  14.        CASE "1"
  15.           GOTO Send
  16.        ENDCASE
  17.        CASE "2"
  18.           GOTO Receive
  19.        ENDCASE
  20.        CASE "3"
  21.           GOTO Finish
  22.        ENDCASE
  23.        CASE "4"
  24.           GOTO Logout
  25.        ENDCASE
  26.        CASE "S"
  27.           GOTO Send
  28.        ENDCASE
  29.        CASE "R"
  30.           GOTO Receive
  31.        ENDCASE
  32.        CASE "F"
  33.           GOTO Finish
  34.        ENDCASE
  35.        CASE "L"
  36.           GOTO Logout
  37.        ENDCASE
  38.     ENDSWITCH
  39. ;
  40. ;    Unrecognized entry
  41. ;
  42.     SOUND 100 500
  43.     GOTO Restart
  44. ;
  45. ;    Exit routine
  46. ;
  47. Exit:
  48.     RESTORE     ; CLose the window we opened in subroutine Window
  49.     EXIT
  50. ;
  51. ;    Command subroutine - build and send a KERMIT packet
  52. ;    .. The body of the packet is in S0
  53. ;
  54. Command:
  55.     N0 = 1        ; Set MARK value (SOH)
  56.     LENGTH S0 N2    ; Compute length of type&data
  57.     N3 = N2+2+32    ; Account for blknum and checksum, and make an ASCII
  58.  
  59.     ITOC N0 S1(0)    ; Set MARK into string
  60.     ITOC N3 S1(1)    ; Set length into string
  61.     S1(2) = " "     ; Set block number
  62.     S1(3:79) = S0    ; Store type and data
  63. ;
  64. ;    Now, compute the checksum
  65. ;
  66.     N4 = 1        ; Start at length variable
  67.     N5 = N2+2    ; Make a loop count
  68.     N6 = 0        ; Initialize summation
  69. Loop:
  70.     CTOI S1(N4:N4) N7
  71.     N6 = N6+N7    ; Sum the value
  72.  
  73.     INC N4        ; Point to next
  74.     DEC N5        ; Decrement count to go
  75.  
  76.     IF NOT ZERO N5    ; Loop for count in
  77.        GOTO Loop    ; .. N5
  78.        ENDIF
  79.  
  80.     N6 = N6-(N6/256)*256    ; Reduce to 8 bits
  81.     N7 = N6/64        ; Extract top 2 bits
  82.     N6 = N6+N7        ; Sum MSBits with low 6 bits
  83.     N6 = N6-(N6/64)*64    ; And reduce result to 6 bits
  84.     N6 = N6+32        ; Make printable ascii
  85. ;
  86. ;    Store the CHECKSUM, and transmit the whole
  87. ;
  88.     N2 = N2+3    ; COmpute index to checksum
  89.     ITOC N6 S1(n2:n2)
  90.     INC N2        ; Point after checksum
  91.     S1(N2) = "!"    ; Store a c/r
  92.     TRANS S1    ; And send it
  93.     RETURN        ; And we're done
  94. ;
  95. ;    Build and send a logout and we're done
  96. ;
  97. Logout:
  98.     S0 = "GL"
  99.     GOSUB Command
  100.     GOTO Exit
  101. ;
  102. ;    Build and send a finish and we're done
  103. ;
  104. Finish:
  105.     S0 = "GF"
  106.     GOSUB Command
  107.     GOTO Exit
  108. ;
  109. ;    Initiate a KERMIT send operation
  110. ;
  111. Send:
  112.     SOUND 400 200
  113.     ATSAY 17 12 (Default) "File name: "
  114.     ATGET 17 27 (Default) 40 S1
  115.  
  116.     IF NOT ISFILE S1
  117.        SOUND 100 500
  118.        ATSAY 17 27 (Default) "File does not exist... please re-enter. "
  119.        PAUSE 5
  120.        GOTO Send
  121.        ENDIF
  122.     SENDFILE KERMIT S1
  123.     GOTO Exit
  124. ;
  125. ;    Initiate a KERMIT receive operation
  126. ;
  127. Receive:
  128.     SOUND 400 200
  129.     ATSAY 17 12 (Default) "File name: "
  130.     ATGET 17 27 (Default) 40 S1
  131.  
  132.     S0 = "R"&S1
  133.     GOSUB Command
  134.     GETFILE KERMIT
  135.     GOTO Exit
  136. ;
  137. ;    Open a window and read a command
  138. ;
  139. Window:
  140.     SAVE 10 10 18 70
  141.     BOX  10 10 18 70 (Default)
  142.     ATSAY 10 12 (Default) " COM-AND Kermit Server "
  143.     ATSAY 11 12 (Default) "(1) Send    (request host to receive file(s))"
  144.     ATSAY 12 12 (Default) "(2) Receive (request host to send file(s))"
  145.     ATSAY 13 12 (Default) "(3) Finish  (terminate host KERMIT server)"
  146.     ATSAY 14 12 (Default) "(4) LogOut  (terminate host server and logoff)"
  147.  
  148.     ATSAY 16 12 (Default) "Enter command: "
  149.     ATGET 16 27 (Default) 2 s0
  150.     UPPER S0    ; Make it upper case
  151.     Return
  152.